﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ChucNang_KhachHangThanThiet_KHTT_NhatKyMuaHang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GlobalFunctions gf = new GlobalFunctions();
        if (gf.IsLogin() == 1 && gf.IsKHTT() == 1)
        {
            //thong ke theo nam hien hanh
            DataDSTableAdapters.DATHANG_TongTienTableAdapter adapter = new DataDSTableAdapters.DATHANG_TongTienTableAdapter();
            DataDSTableAdapters.TAIKHOANTableAdapter tkadapter = new DataDSTableAdapters.TAIKHOANTableAdapter();
            DataDS.TAIKHOANDataTable tktable = new DataDS.TAIKHOANDataTable();
            int id_tk = gf.getLoginId();


            tktable = tkadapter.TAIKHOAN_LayTheoId(id_tk);

            lbTenKhachHang.Text = tktable[0].HoTen;
            lbCMND.Text = tktable.Rows[0]["CMND"].ToString();
            lbDiaChi.Text = tktable[0].DiaChi;
            lbDienThoai.Text = tktable[0].DienThoai;


            DataDS.DATHANG_TongTienDataTable dhTable = adapter.DATHANG_TinhTongTienTrongNamTheoIdTaiKhoan(id_tk);
            double sumyear = dhTable[0].TongTienTrongNam;
            lbTrongNam.Text = sumyear.ToString();



            DataDSTableAdapters.DATHANG_CHITIETDATHANG_SANPHAMTableAdapter adapter2 = new DataDSTableAdapters.DATHANG_CHITIETDATHANG_SANPHAMTableAdapter();
            GridView2.DataSource = adapter2.DATHANG_CHITIETDATHANG_SANPHAM_ThongKeMuaHangKhachHangTheoNam(DateTime.Now.Year, id_tk);
            GridView2.DataBind();

            DataDSTableAdapters.DATHANGTableAdapter dhAdapter = new DataDSTableAdapters.DATHANGTableAdapter();
            DataDS.DATHANGDataTable tb = dhAdapter.DATHANG_LayTheoIdTaiKhoan(id_tk);
            double sum = 0;
            for (int i = 0; i < tb.Rows.Count; i++ )
            {
                sum += tb[i].TongTien;
            }
            lbTatCa.Text = sum.ToString();
            GridView1.DataSource = dhAdapter.DATHANG_ThongKeMuaHangKhachHangTheoNam(id_tk);
            GridView1.DataBind();

        }
        else
            Response.Redirect("/SMO/ChucNang/NguoiDung/NguoiDung_DangNhap.aspx");
    }
}
